package com.leetao.wxmsg.framework.domain;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.HashMap;

/**
 * 微信消息
 * @author 菅江晖
 * @date 2021/3/8 - 11:27
 */
public class WxMsg {

    String touser;

    @JSONField(name = "template_id")
    String templateId;

    String page;

    @JSONField(name = "miniprogram_state")
    String miniprogramState = "formal";

    String lang = "zh_CN";

    final HashMap<String,Entry> data = new HashMap<>(16);

    public String getTouser() {
        return touser;
    }

    public void setTouser(String touser) {
        this.touser = touser;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public String getTemplateId() {
        return templateId;
    }

    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }

    public String getMiniprogramState() {
        return miniprogramState;
    }

    public void setMiniprogramState(String miniprogramState) {
        this.miniprogramState = miniprogramState;
    }

    public HashMap<String, Entry> getData() {
        return data;
    }

    public String getLang() {
        return lang;
    }

    public void setLang(String lang) {
        this.lang = lang;
    }

    public void setDataEntry(String key, String value) {
        data.put(key,new Entry(value));
    }


    private static class Entry {
        String value;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public Entry(String value) {
            this.value = value;
        }
    }

    public static Builder create() {
        return new Builder();
    }


    public static class Builder {
        WxMsg wxMsg = new WxMsg();

        public Builder setTouser(String touser) {
            wxMsg.setTouser(touser);
            return this;
        }

        public Builder setPage(String page) {
            wxMsg.setPage(page);
            return this;
        }

        public Builder setTemplateId(String templateId) {
            wxMsg.setTemplateId(templateId);
            return this;
        }

        public Builder setMiniprogramState(String miniprogramState) {
            wxMsg.setMiniprogramState(miniprogramState);
            return this;
        }

        public Builder setLang(String lang) {
            wxMsg.setLang(lang);
            return this;
        }

        public Builder setDataEntry(String key, String value) {
            wxMsg.setDataEntry(key,value);
            return this;
        }

        public WxMsg create() {
            return wxMsg;
        }
    }

}
